﻿

/*
 *  GTA IV VehicleWeaponsMod 0.0.2.0
 *  GhostGum - 2009
 *  
 *  Installation: Put 'VehicleWeaponsMod.Net.dll' in GTA\Scripts\ directory.
 *  Requires GTAScript.Net 0.0.3.0 - http://www.gtaforums.com/index.php?showtopic=435532
 *  
 * Usage: Vehicle Weapons Shops will be spawned at specific places on the map (mostly near safehouses), you will see a blip on your map when you are near. 
 * Just enter the VehicleWeapons Shop blip & you will be taken to the shop menu.
 */





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VehicleWeaponsMod
{
    public class VehicleWeaponsScript : GTA.ScriptBase
    {
        public static VehicleWeapon[] Weapons;
        bool isFiring = false;
        bool hasloaded = false;

        public static VehicleWeaponsShop[] Shops;

        public VehicleWeaponsScript()
        {
            new Log("VehicleWeaponsScript", true);
            if (GTA.Version.GTAScriptVersion != 30) Log.Warning("GTAScript version not supported! Expected: 0.0.3.0, Found: " + GTA.Version.GTAScriptVersionIdentifier);
            GTA.Events.OnStart.Handler += OnStart;
            GTA.Events.RunTick.Handler += RunTick;
            GTA.Events.KeyDown.Handler += OnKeyDown;
            GTA.Events.KeyUp.Handler += OnKeyUp;
            GTA.Events.CleanUp.Handler += CleanUp;
        }

        public void OnStart(Object sender, EventArgs args)
        {
            Log.Message("OnStart");
            Weapons = new VehicleWeapon[3];
            for (int i = 0; i < Weapons.Length; i++)
            {
                Weapons[i] = new VehicleWeapon();
            }

            
            Shops = new VehicleWeaponsShop[5];
            for (int i = 0; i < Shops.Length; i++)
            {
                Shops[i] = new VehicleWeaponsShop();
            }

            // Broker safehouse
            Shops[0].ShopBlipLoc = new GTA.Vector3(934.6243F, -501.312F, 14.77346F);
            Shops[0].ShopBlipDirection = new GTA.Vector3(0.0F,262.2531F,0.0F);
            Shops[0].GarageVehicleLoc = new GTA.Vector3(933.6804F,-512.7776F,14.52348F);
            Shops[0].GarageVehicleDirection = new GTA.Vector3(0.0F,268.3926F,0.0F);
            Shops[0].GarageCamLoc = new GTA.Vector3(939.3219F, -516.2585F, 17.0731F);
            Shops[0].GarageCamDirection = new GTA.Vector3(-16.51887F, -4.268868F, 62.65061F);
            Shops[0].ShopExitLoc = new GTA.Vector3(940.1938F, -531.9634F, 14.23782F);
            Shops[0].ShopExitDirection = new GTA.Vector3(0.0F, 89.92955F, 0.0F);
            
            // Bohan safehouse
            Shops[1].ShopBlipLoc = new GTA.Vector3(628.2784F, 1470.627F, 11.65722F);
            Shops[1].ShopBlipDirection = new GTA.Vector3(0.0F, 278.4503F, 0.0F);
            Shops[1].GarageVehicleLoc = new GTA.Vector3(618.7659F, 1477.933F, 12.45758F);
            Shops[1].GarageVehicleDirection = new GTA.Vector3(0.0F, 178.0265F, 0.0F);
            Shops[1].GarageCamLoc = new GTA.Vector3(615.8345F, 1472.503F, 16.14194F);
            Shops[1].GarageCamDirection = new GTA.Vector3(-26.7101F, 0F, 16.14194F);
            Shops[1].ShopExitLoc = new GTA.Vector3(618.9461F, 1466.997F, 11.3852F);
            Shops[1].ShopExitDirection = new GTA.Vector3(0.0F, 182.1399F, 0.0F);

            // Algonquin Middle Park East Safehouse
            Shops[2].ShopBlipLoc = new GTA.Vector3(48.65836F, 805.4033F, 14.26535F);
            Shops[2].ShopBlipDirection = new GTA.Vector3(0.0F, 359.6738F, 0.0F);
            Shops[2].GarageVehicleLoc = new GTA.Vector3(73.45475F, 800.4845F, 14.76714F);
            Shops[2].GarageVehicleDirection = new GTA.Vector3(0.0F, 268.9761F, 0.0F);
            Shops[2].GarageCamLoc = new GTA.Vector3(79.9792F, 799.797F, 17.5345F);
            Shops[2].GarageCamDirection = new GTA.Vector3(-18.41568F, -5.336085E-08F, 88.35538F);
            Shops[2].ShopExitLoc = new GTA.Vector3(73.87724F, 800.165F, 14.76729F);
            Shops[2].ShopExitDirection = new GTA.Vector3(0.0F, 89.96925F, 0.0F);

            // Algonquin Northwood Safehouse
            Shops[3].ShopBlipLoc = new GTA.Vector3(-587.6743F, 1469.368F, 9.549331F);
            Shops[3].ShopBlipDirection = new GTA.Vector3(0.0F, 162.8337F, 0.0F);
            Shops[3].GarageVehicleLoc = new GTA.Vector3(-579.8888F, 1460.502F, 9.520077F);
            Shops[3].GarageVehicleDirection = new GTA.Vector3(0.0F, 253.485F, 0.0F);
            Shops[3].GarageCamLoc = new GTA.Vector3(-576.3041F, 1455.111F, 12.5336F);
            Shops[3].GarageCamDirection = new GTA.Vector3(-20.58591F, -8.537736E-07F, 38.05401F);
            Shops[3].ShopExitLoc = new GTA.Vector3(-580.2979F, 1460.585F, 9.51918F);
            Shops[3].ShopExitDirection = new GTA.Vector3(0.0F, 255.6594F, 0.0F);

            // Alderney City Safehouse
            Shops[4].ShopBlipLoc = new GTA.Vector3(-1298.045F, 1088.088F, 19.10025F);
            Shops[4].ShopBlipDirection = new GTA.Vector3(0.0F, 0.6963008F, 0.0F);
            Shops[4].GarageVehicleLoc = new GTA.Vector3(-1291.171F, 1113.75F, 21.47845F);
            Shops[4].GarageVehicleDirection = new GTA.Vector3(0.0F, 358.7595F, 0.0F);
            Shops[4].GarageCamLoc = new GTA.Vector3(-1290.298F, 1120.216F, 23.48233F);
            Shops[4].GarageCamDirection = new GTA.Vector3(-12.26675F, 5.336085F, 176.7121F);
            Shops[4].ShopExitLoc = new GTA.Vector3(-1296.292F, 1104.332F, 19.2011F);
            Shops[4].ShopExitDirection = new GTA.Vector3(0.0F, 181.0668F, 0.0F);

            hasloaded = true;
            Log.Debug("VehicleWeaponsScript Started");
        }

        public void RunTick(Object sender, EventArgs args)
        {
            if (!hasloaded) return;
            for (int i = 0; i < Weapons.Length; i++)
            {
                if ((Weapons[i].isAttachedToCurrentVehicle))
                {
                    if (isFiring) Weapons[i].FireWeapon();
                }
            }
        }

        public void OnKeyDown(Object sender, GTA.Events.KeyEventArgs args)
        {
            if (!hasloaded) return;
            if (args.KeyCode == GTA.Keys.LButton)
            { // fire weapon
                for (int i = 0; i < Weapons.Length; i++)
                {
                    if (Weapons[i].isAttachedToCurrentVehicle) isFiring = true;
                }
            }
            if (args.KeyCode == GTA.Keys.Escape)
            {
                for (int i = 0; i < Shops.Length; i++)
                {
                    if (Shops[i].IsShopping) Shops[i].ShopForm.btn_close_Click(null, new EventArgs());
                }
            }
            if (args.KeyCode == GTA.Keys.Enter)
            {
                for (int i = 0; i < Shops.Length; i++)
                {
                    if (Shops[i].IsShopping) Shops[i].ShopForm.btn_buy_Click(null, new EventArgs());
                }
            }
        }

        public void OnKeyUp(Object sender, GTA.Events.KeyEventArgs args)
        {
            if (!hasloaded) return;
            if (args.KeyCode == GTA.Keys.LButton)
            { // stop firing
                isFiring = false;
            }
        }

        public void CleanUp(Object sender, GTA.Events.CleanUpEventArgs args)
        { // clean up all our objects & markers on script unload
            if (!hasloaded) return;
            if ((args.Script != this) && (args.Script != null)) return; // only cleanup if it is this script closing, or a gloabl close of all scripts
            Log.Debug("VehicleWeaponsScript.CleanUp()");
            hasloaded = false;
            for (int i = 0; i < Shops.Length; i++)
            {
                if (Shops[i] == null) continue;
                Shops[i].CleanUp();
                Shops[i] = null;
            }
            Shops = null;
            
            for (int i = 0; i < Weapons.Length; i++)
            {
                if (Weapons[i] == null) continue;
                Weapons[i].CleanUp();
                Weapons[i] = null;
            }
            Weapons = null;
            
            Log.Debug("VehicleWeaponScript.CleanUp() done");

        }
    }

}







